package cn.iocoder.yudao.module.system.controller.admin.patentapplication.vo;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import cn.iocoder.yudao.framework.common.DictTypeConstants;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
import static java.util.stream.Collectors.toList;

@Data
@Schema(description = "管理后台 - 会员专利申请 Response VO")
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper=true)
@ExcelIgnoreUnannotated
public class PatentApplicationNewRespVO extends TenantBaseDO {
    @ExcelProperty("id")
    @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "22877")
    private Long id;
    @ExcelProperty("创建时间")
    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
    private LocalDateTime createTime;
    @ExcelProperty("答复期限")
    @Schema(description = "答复期限")
    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY,timezone = "GMT+8")
    @DateTimeFormat(pattern=FORMAT_YEAR_MONTH_DAY)
    private LocalDate responseDeadline;
    @ExcelProperty("案件id")
    @Schema(description = "案件id", example = "30321")
    private Long caseId;
    @ExcelProperty("上传日期")
    @Schema(description = "上传日期")
    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY,timezone = "GMT+8")
    @DateTimeFormat(pattern=FORMAT_YEAR_MONTH_DAY)
    private LocalDate uploadDate;
    @ExcelProperty("普通用户id")
    @Schema(description = "普通用户id", example = "2822")
    private Long userId;
    @ExcelProperty("其他文件")
    @Schema(description = "其他文件")
    private List<String>reviewMaterialsFiles=new ArrayList<>();
    @Schema(description = "返稿文件")
    @ExcelProperty("返稿文件")
    private String returnFiles;
    @ExcelProperty("案件名称")
    @Schema(description = "案件名称", example = "案件名称")
    private String caseName;
    @ExcelProperty("撰写人id")
    @Schema(description = "撰写人id")
    private Long reviewerBy;
    @ExcelProperty("撰写人")
    @Schema(description = "撰写人", example = "")
    private String reviewer;
    @ExcelProperty("企业名称")
    @Schema(description = "企业名称", example = "")
    private String enterprise;
    @ExcelProperty("是否上传返稿文件")
    @Schema(description = "是否上传返稿文件", example = "")
    private Boolean ifUpload;
    @DictFormat(DictTypeConstants.PAYMENT_STATUS)
    @Schema(description = "费用缴纳状态", example =
    "费用缴纳状态" +
    "payment_status" +
    "1,已缴年费" +
    "2,未缴年费" +
    "3,已缴申请费" +
    "4,未缴申请费")
    private String paymentStatus;
    @Schema(description = "案件状态", example =
    "案件状态" +
    "case_status" +
    "1,撰写中" +
    "2,待提交" +
    "3,待补充" +
    "4,受理" +
    "5,初审中" +
    "6,实质审查中" +
    "7,审查答复中" +
    "8,补正中" +
    "9,驳回" +
    "10,代办登记" +
    "11,授权" +
    "12,未缴费过期" +
    "13,恢复中" +
    "14,转让中")
    @DictFormat(DictTypeConstants.CASE_STATUS)
    private String caseStatus;
    @DictFormat(DictTypeConstants.CASE_TYPE)
    @Schema(description = "案件状态", example =
    "案件类型"+
    "case_type"+
    "1,软著"+
    "2,商标"+
    "3,实用新型"+
    "4,发明专利"+
    "5,外观专利")
    private String caseType;
    @Schema(description = "更新时间", example = "")
    private String updateTimeStr;
    @ExcelProperty("是否上传返稿文件")
    @Schema(description = "是否逾期 true 是 ,false 否")
    private Boolean ifLate=false;
    @Schema(description = "上次提醒时间")
    private LocalDate remindTime;
    @Schema(description = "今天是否提醒过 true 是 false 否")
    private Boolean remindedToday;
    @Schema(description = "手机号码")
    private String mobile;


    public Boolean getIfUpload(){return !StrUtil.isBlank(returnFiles);}
    public String getCaseTypeText(){if(StrUtil.isBlank(caseType)){return "";}
    return DictFrameworkUtils.getDictDataLabel(DictTypeConstants.CASE_TYPE,caseType);}
    public String getPaymentStatusText(){if(StrUtil.isBlank(paymentStatus)){return "";}
    return DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PAYMENT_STATUS,paymentStatus);}
    public String getCaseStatusText(){if(StrUtil.isBlank(caseStatus)){return "";}
    return DictFrameworkUtils.getDictDataLabel(DictTypeConstants.CASE_STATUS,caseStatus);}
    public String getUpdateTimeText(){LocalDateTime updateTime = super.getUpdateTime();if(ObjectUtil.isNull(updateTime)){return "";}
    return updateTime.format(DateTimeFormatter.ofPattern(FORMAT_YEAR_MONTH_DAY));}
    public Boolean getIfLate(){if(ObjectUtil.isNull(responseDeadline)){return false;}else{
    if(ObjectUtil.isNotNull(uploadDate)){return responseDeadline.isAfter(uploadDate);
    }else {return responseDeadline.isAfter(LocalDate.now());}}}
    public Boolean getRemindedToday(){if(ObjectUtil.isNull(remindTime)){return false;}
    return remindTime.isEqual(LocalDate.now());}
    public List<Map<String,String>>getReviewMaterialsFilesData(){
    if (reviewMaterialsFiles.isEmpty()) {
        return new ArrayList<>();
    }
    return reviewMaterialsFiles.stream().map(rmf->{
    Map<String, String>data=new HashMap<>();
    int lastSlashIndex = rmf.lastIndexOf("/");
    if (lastSlashIndex == -1 || lastSlashIndex + 14 >= rmf.length()) {
    data.put("fileName", rmf);
    data.put("url", rmf);
    return data;
    }
    String fileName = rmf.substring(lastSlashIndex + 14);
    data.put("fileName", fileName);
    data.put("url", rmf);
    return data;
    })
    .collect(toList());
    }
}